package cn.jaye.fabric.controller;

import cn.jaye.fabric.application.AccessPointApiPackageApplicationService;
import cn.jaye.fabric.application.command.BindApiPackageCommand;
import cn.jaye.fabric.common.util.ResultUtil;
import com.alibaba.fastjson.JSON;
import cn.jaye.fabric.common.constant.ExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jaye
 * @create 2017-12-29 15:12
 */
@RestController
@RequestMapping("/tenant/apipackage")
public class AccessPointApiPackageController {

    @Autowired
    private AccessPointApiPackageApplicationService accessPointApiPackageApplicationService;

    @PostMapping("/list")
    public String listAllApis(@RequestBody String data) {
        return accessPointApiPackageApplicationService.listAccessPointApiPackage();
    }

    @PostMapping("/bind")
    public String bindAllApis(@RequestBody String data) {
        BindApiPackageCommand bindApiPackageCommand = JSON.parseObject(data, BindApiPackageCommand.class);
        if (accessPointApiPackageApplicationService.bindApiPackage(bindApiPackageCommand)) {
            return ResultUtil.success(null);
        }
        return ResultUtil.error(ExceptionEnum.TENANT_APIPACKAGE_BIND_FAILED);
    }
}
